package pack0812;

public class DemoC {
    public static void main(String[] args) {
        int[] array = {6,5,3,9,65,45,25,63,51,57,85,95,45,65};
        for(int i = 0; i<array.length-1;i++){
            for(int j = 0;j<array.length-1-i;j++){
                if(array[j]>array[j+1]){
                    int a =array[j];
                    array[j] = array[j+1];
                    array[j+1] = a;
                }
            }
        }
        for(int i = 0;i<array.length;i++){
            System.out.print(array[i]+"\t");
        }
        System.out.println();
        //二分法
        int a = 63;
        int begin = 0, end = array.length-1,middle = 0;
        while(true){
            middle = (begin+end)/2;
            if(array[middle]==a){
                System.out.println("是数组的第"+middle+"个");
                break;
            }else if(array[middle]>a){
                end = middle-1;
            }else{
                begin = middle+1;
            }
        }
        System.out.println(array[middle]);
    }
}
